export interface AccountNetModel {
  real_name: string;
  expend_integral: number,
  integral: number,
  username: string,
  headimgurl: string,
  id: string,
  real_name_status: number,
  avatar_check: number,
  username_check: number,
  sex: number,
  job_collect_count: number,
  tel: string
}


export interface VipStatusNetModel {
  status: number,
  label: string
}

export class AccountBasicEntity {
  uid: string;
  sex: string;
  jobCollectCount: number;
  avatarUrl: string;
  username: string;
  integral: number;
  expendIntegral: number;
  realName: string;
  tel: string;

  constructor(netModel: AccountNetModel) {
    this.uid = netModel.id;
    this.sex = netModel.sex == 1 ? "男" : "女";
    this.jobCollectCount = netModel.job_collect_count;
    this.avatarUrl = netModel.headimgurl;
    this.username = netModel.username;
    this.integral = netModel.integral;
    this.expendIntegral = netModel.expend_integral;
    this.realName = netModel.real_name;
    this.tel = netModel.tel;
  }

  static asEntity(accountNetModel: AccountNetModel): AccountBasicEntity {
    return new AccountBasicEntity(accountNetModel);
  }
}

export class AccountAuthEntity {
  realNameStatus: boolean;
  avatarCheck: boolean;
  usernameCheck: boolean;

  constructor(netModel: AccountNetModel) {
    this.realNameStatus = netModel.real_name_status == 1;
    this.avatarCheck = netModel.avatar_check == 1;
    this.usernameCheck = netModel.username_check == 1;
  }

  static asEntity(accountNetModel: AccountNetModel): AccountAuthEntity {
    return new AccountAuthEntity(accountNetModel);
  }
}

export class VipStatusEntity {
  status: number;
  label: string;

  constructor(vipStatusNetModel: VipStatusNetModel) {
    this.status = vipStatusNetModel.status;
    this.label = vipStatusNetModel.label;
  }

  static asEntity(vipStatusNetModel: VipStatusNetModel): VipStatusEntity {
    return new VipStatusEntity(vipStatusNetModel);
  }
}

export class AccountEntity {

  accountBasic: AccountBasicEntity;
  accountAuth: AccountAuthEntity;
  vipStatus: VipStatusEntity;


  constructor(accountBasic: AccountBasicEntity, accountAuth: AccountAuthEntity, vipStatus: VipStatusEntity) {
    this.accountBasic = accountBasic;
    this.accountAuth = accountAuth;
    // this.vipStatus = new VipStatusEntity(vipStatus.status || 0, vipStatus.label || "");
    this.vipStatus = vipStatus;
  }

  nickname(): string {
    if (this.accountBasic.realName) {
      return this.accountBasic.realName;
    } else {
      return this.accountBasic.username;
    }
  }

  isOpenVip(): boolean {
    return this.vipStatus.status == 1;
  }

  static toAccountEntity(account: AccountNetModel, vipStatus: VipStatusNetModel): AccountEntity {
    return new AccountEntity(AccountBasicEntity.asEntity(account), AccountAuthEntity.asEntity(account), VipStatusEntity.asEntity(vipStatus));
  }
}
